<template>
  <div class="login-container">
    <div class="login-container__box">
      <div class="login-container__box__left">
        <span class="title">欢迎登录 {{ APP_TITLE }}</span>
        <div class="fTitle">高质量代码的通用快速开发平台</div>
        <img src="@/assets/img/login/left_bg.png" :alt="APP_TITLE" />
        <div class="scroll-text">
          <span
            >放假通知：2024年新年佳节将至，根据国家相关规定并结合公司实际情况，现将春节放假时间通知如下!</span
          >
        </div>
      </div>
      <div class="login-container__box__right">
        <span class="title">账号登录</span>
        <a-form
          class="form"
          ref="form"
          :model="loginForm"
          :rules="rules"
          @finish="_handleLogin"
        >
          <a-form-item name="username">
            <a-input
              v-model:value="loginForm.username"
              placeholder="请输入账号"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item name="password">
            <a-input-password
              password
              v-model:value="loginForm.password"
              placeholder="请输入密码"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item class="capture" name="code">
            <a-input
              :maxlength="4"
              v-model:value="loginForm.code"
              placeholder="请输入验证码"
              style="width: 65%"
            />
            <img
              src=""
              alt="验证码"
            />
          </a-form-item>
          <a-form-item class="capture">
            <a-checkbox v-model:checked="checked"
              >记住密码 （账号：super-admin 密码：123456）</a-checkbox
            >
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 24 }">
            <a-button
              class="button"
              type="primary"
              html-type="submit"
              :loading="loading"
            >
              <span>登录</span>
            </a-button>
          </a-form-item>
        </a-form>
        <a-divider>
          <span class="text-line">其它登录方式</span>
        </a-divider>
        <div class="login-container__box__right__methods">
          <img src="@/assets/img/login/qq-icon.png" alt="qq" />
          <img src="@/assets/img/login/wechat-icon.png" alt="wechat" />
          <img src="@/assets/img/login/weibo-icon.png" alt="weibo" />
          <img src="@/assets/img/login/feishu-icon.png" alt="feishu" />
          <img src="@/assets/img/login/douyin-icon.png" alt="douyin" />
          <img src="@/assets/img/login/ali-icon.png" alt="ali" />
          <img src="@/assets/img/login/google-icon.png" alt="google" />
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { rules } from '@/views/login/rule'
import { useLoginEffect } from './useLoginEffect'
import { useStore } from 'vuex'
import { message } from 'ant-design-vue'
import { useRouter } from 'vue-router'
import { HOME_ROUTE_NAME } from '@/router/constants'
const APP_TITLE = process.env.VUE_APP_TITLE
const router = useRouter()
const store = useStore()
// 数据源及验证规则
const form = ref(null)
const loginForm = reactive({
  username: '',
  password: '',
  code: '1111'
})
const checked = ref(true)
// 记住密码相关逻辑
const { initForm, handleRemember } = useLoginEffect(checked, loginForm)
// 初始化表单 - 如果有记住密码的话
initForm()
// 登录动作相关
const loading = ref(false)
const _handleLogin = async (values) => {
  loading.value = true
  handleRemember(values)
  try {
    const result = await store.dispatch('user/login', values)
    if (!result.success) return false
    message.success(result.message)
    router.push({
      name: HOME_ROUTE_NAME
    })
  } finally {
    loading.value = false
  }
}
</script>
<style scoped lang="scss">
@import '../../styles/mixin.scss';
.login-container {
  background-image: url('~../../assets/img/login/login_bg.png');
  background-size: cover;
  background-repeat: no-repeat;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  &__box {
    display: flex;
    flex-direction: row;
    > div {
      width: 444px;
      height: 570px;
      box-sizing: border-box;
    }
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    &__left {
      border-top-left-radius: 12px;
      border-bottom-left-radius: 12px;

      @include flex-column-center;
      box-shadow: 0 16px 73px 8px #cbcbcb33;
      padding: 23px 25px;
      .title {
        font-size: 26px;
        font-weight: 700;
        color: #000;
      }
      .fTitle {
        @include flex-row-center;
        padding: 10px 40px;
        border-top-left-radius: 20px;
        border-bottom-left-radius: 20px;
        border-top-right-radius: 20px;
        margin-top: 20px;
        background-color: #1354fd;
        color: #f6faff;
        font-size: 18px;
        font-weight: 700;
      }
      img {
        height: 70%;
        margin-top: 30px;
      }
      @keyframes scroll {
        0% {
          transform: translateX(100%);
        }
        100% {
          transform: translateX(-100%);
        }
      }
      .scroll-text {
        width: 90%;
        overflow: hidden;
        font-size: 12px;
        font-weight: 500;
        text-align: center;
        color: #333;
        cursor: pointer;
        &:hover {
          color: #1677ff;
        }
        span {
          display: inline-block;
          width: 100%;
          white-space: nowrap;
          animation: scroll 10s linear infinite;
        }
      }
    }
    &__right {
      border-top-right-radius: 12px;
      border-bottom-right-radius: 12px;
      padding: 34px 42px;
      background-color: #fff;
      @include flex-column-center;
      .title {
        font-size: 30px;
        font-weight: 700;
        text-align: center;
        color: #1e1e1e;
        margin-bottom: 35px;
      }
      .form {
        width: 100%;
        .ant-input,
        .ant-input-affix-wrapper {
          height: 44px;
          border: 1px solid #ededed;
          border-radius: 4px;
          max-width: 100%;
        }
        .ant-form-item-control-input-content {
          display: flex;
          flex-direction: row;
          align-items: center;
        }
        .capture {
          img {
            flex: 1;
          }
        }
        .button {
          width: 100%;
          height: 50px;
          > span {
            letter-spacing: 2px;
            font-size: 15px;
            font-weight: bold;
          }
        }
      }
      .text-line {
        font-size: 14px;
        font-weight: 500;
        color: #a1aebe;
      }
      &__methods {
        width: 100%;
        @include flex-row-center;
        justify-content: space-between;
        > img {
          width: 30px;
          height: 30px;
        }
      }
    }
  }
}
</style>
